home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / pcr / pcr4_4.lha / DIST / gc / GCglobals.c < prev    next >
C/C++ Source or Header  |  1991-10-09  |  9KB  |  245 lines

  1. /* begincopyright
  2.   Copyright (c) 1988,1990 Xerox Corporation. All rights reserved.
  3.   Use and copying of this software and preparation of derivative works based
  4.   upon this software are permitted. Any distribution of this software or
  5.   derivative works must comply with all applicable United States export
  6.   control laws. This software is made available AS IS, and Xerox Corporation
  7.   makes no warranty about the software, its performance or its conformity to
  8.   any specification. Any person obtaining a copy of this software is requested
  9.   to send their name and post office or electronic mail address to:
  10.     PCR Coordinator
  11.     Xerox PARC
  12.     3333 Coyote Hill Rd.
  13.     Palo Alto, CA 94304
  14.     
  15.   Parts of this software were derived from code bearing the copyright notice:
  16.   
  17.   Copyright 1988, 1989 Hans-J. Boehm, Alan J. Demers
  18.   This material may be freely distributed, provided this notice is retained.
  19.   This material is provided as is, with no warranty expressed or implied.
  20.   Use at your own risk.
  21.   
  22.   endcopyright */
  23.   
  24. # include "xr/GCPrivate.h"
  25. # include "xr/GCVirtualDirty.h"
  26.  
  27. /*
  28.  * Boehm, January 15, 1991 4:23:14 pm PST
  29.  */
  30.  
  31. /* Initialized variable declarations for garbage collector globals.  Needed */
  32. /* to ensure that they all end up in contiguous memory in the data segment  */
  33. /* rather than in separate common blocks.                    */
  34. /* Many are set to their real initial values by executable code.        */
  35.  
  36. word GC_first_global = 0;
  37.  
  38. /* Public variables.  May be altered by client. */
  39. bool GC_dont_gc = FALSE;    /* inhibit collection      */
  40. bool GC_fix_heap_size = FALSE;        /* inhibit heap expansion  */
  41. long GC_non_gc_bytes = 0;   /* Number of bytes declared to be uncollectable. */
  42. bool GC_markCarefully = FALSE;  /* Full collections should minimize working */
  43.                 /* set rather than cpu time.            */
  44. bool GC_safe_to_gc_print = FALSE; /* OK to produce messages with xr_printf */
  45. bool GC_ok_to_panic = TRUE;   /* OK to call XR_panic if things go completely  */
  46.                   /* haywire.  Dont turn this off without a VERY  */
  47.                   /* good reason.                      */
  48. unsigned GC_partial_gc_allocs = 0; 
  49. unsigned GC_full_gc_allocs = FULL_GC_ALLOCS;
  50.  
  51. unsigned GC_free_mem_ratio = FREE_MEM_RATIO; /* Heap expansion factor */
  52.  
  53. /* Public variables.  Read only for the client.  Set by collector. */
  54. char * GC_heapstart = 0; /* A lower bound on all heap addresses */
  55.                  /* Known to be HBLKSIZE aligned.       */
  56.  
  57. char * GC_heaplim = 0;   /* 1 + last address in heap */
  58.  
  59. long GC_heapsize = 0;       /* Heap size in bytes */
  60.  
  61. char * GC_sys_mem_end = 0; /* 1 + end of memory allocated from system.  */
  62.                /* May differ from GC_heaplim if other    */
  63.                /* allocation, e.g. for block headers    */
  64.                /* is going on.                */
  65.  
  66. long GC_mem_found = 0;   /* Number of words reclaimed since start of last */
  67.                  /* collection.  Approximate.              */
  68.              
  69. long GC_mem_freed = 0;  /* Number of longwords explicitly       */
  70.             /* freed since last garbage collection. */
  71.              
  72. long GC_composite_in_use = 0;  /* Number of longwords in accessible composite */
  73.                    /* objects.                                    */
  74.  
  75. long GC_atomic_in_use = 0;     /* Number of longwords in accessible atomic */
  76.                    /* objects.                                 */
  77.                    /* Both of the above numbers are good upper */
  78.                    /* bounds.                       */
  79.  
  80. long GC_objects_in_use = 0;    /* Number of live objects found during last */
  81.                    /* collection.                       */
  82.                    
  83. bool GC_running_exclusive = FALSE;  /* True if a single process has taken */
  84.                                     /* over all the processors. */
  85.  
  86. long GC_markfaults = 0; /* The number of page faults that occurred during the */
  87.                 /* last mark phase.                                  */    
  88.              
  89. long GC_max_markfaults = 0; /* The recent max of above */
  90.  
  91. long GC_gc_no = 0;                /* How many times have we collected? */
  92.  
  93. bool GC_demand_collection = FALSE;  /* Someone wants a collection done */
  94.  
  95. long GC_tenure_count = 0;         /* Number of scanned, tenured blocks */
  96.  
  97. unsigned GC_words_allocd = 0;        /* Number of words allocated since last */
  98.                     /* collection.                */
  99.                     
  100. unsigned GC_words_allocd_before_gc = 0;
  101.                       /* Words allocated up to last garbage   */
  102.                     /* collection.  The sum of this and the */
  103.                     /* preceding variable is the total      */
  104.                     /* number of words allocated since the  */
  105.                     /* beginning of the world.              */
  106.                     
  107. unsigned GC_objects_allocd = 0;        /* Number of objects allocated since last */
  108.                     /* collection.                  */
  109.                     
  110. unsigned GC_objects_allocd_before_gc = 0; /* Objects allocated up to last    */
  111.                           /* garbage collection.             */
  112.  
  113. int GC_n_maps_cached = 0;
  114.                     /* The number of heap block maps currently in the cache */
  115.  
  116. int GC_words_at_full_gc = 0;  /* words accessible after full gc */
  117.  
  118. int GC_composite_at_full_gc = 0;  /* composite words accessible after full gc */
  119.  
  120. /* Private to the collector: */
  121. unsigned GC_mode = 0;
  122. unsigned GC_requested_mode = 0;
  123.  
  124. struct hblk * GC_hblkfreelist = (struct hblk *)0; 
  125.  
  126. # ifdef PRINTSTATS
  127.     long GC_reclaim_count = 0;     /* Number of reclaimed small object blocks */
  128. # endif
  129.  
  130. long GC_my_composite_in_use = 0;
  131. long GC_my_atomic_in_use = 0;
  132. long GC_my_objects_in_use = 0;
  133.  
  134. long GC_sp_at_alloc = 0;    /* approximate stack pointer at allocator */
  135.                 /* invocation.                  */
  136.                 
  137. # ifdef SEPARATE_HEADERS
  138.   hdr * GC_hdr_fl = HDR_NIL;    /* Free list for heap block headers */
  139. # endif
  140.  
  141. /* Monitor locks for allocation, tracing, and allocator callback */
  142. /* respectively.                         */
  143. struct XR_MLRep GC_allocate_ml = {0};
  144. struct XR_MLRep GC_alloc_callback_ml = {0};
  145.  
  146. /* Garbage collector callbacks: */
  147. RegisterGCCallbackType GC_callBackBefore = (RegisterGCCallbackType)0;
  148. RegisterGCCallbackType GC_callBackAfter = (RegisterGCCallbackType)0;
  149. RegisterGCCallbackType GC_callBackDuring = (RegisterGCCallbackType)0;
  150. XR_Pointer GC_callBackBeforeClientData = (XR_Pointer)0;
  151. XR_Pointer GC_callBackAfterClientData = (XR_Pointer)0;
  152. XR_Pointer GC_callBackDuringClientData = (XR_Pointer)0;
  153.  
  154. /* Mark stack: */
  155. word * GC_mark_stack_bottom = (word *)0;
  156. word * GC_mark_stack_top = (word *)0;
  157.  
  158. /* List of root segments for marking: */
  159. long GC_num_data = 0;   /* Number of entries in GC_data_list */
  160.  
  161. struct data_list GC_data_list[MAX_DATA_LIST] = {{0}};
  162.                     /* List of all data areas that must be treated as roots */
  163.                     /* by the collector.                    */
  164.  
  165. /* Object free lists */
  166. struct obj * GC_aobjfreelist[MAXOBJSZ+1] = {(struct obj *)0};
  167. struct obj * GC_objfreelist[MAXOBJSZ+1] = {(struct obj *)0};
  168.  
  169. /* Map of block use. */
  170. char GC_hblkmap[MAP_SIZE] = {0};
  171.  
  172. /* Pages with known false references */
  173. # ifdef BLACK_LIST
  174.     char GC_blacklist[MAP_SIZE] = 0;    /* Nonzero ==> false reference */
  175. # endif
  176.  
  177.  
  178. /* Virtual dirty bit stuff. */
  179.   /* Private arrays for GCVirtualDirty.c.  Must be inside the area     */
  180.   /* delimited by GC_first_global and GC_last_global, and separated    */
  181.   /* from either end by at least a page, so they don't get protected.    */
  182.   char VD_Status[VDS_SIZE] = {0};
  183.  
  184.   char VD_Clients[VDS_SIZE] = {0};
  185.  
  186.   /* Other virtual dirty bit related variables that must be here. */
  187.  
  188.   int XR_explicitly_unprotected_pages = 0;
  189.   int XR_wasted_preparation_calls = 0;
  190.   int XR_protection_violations = 0;
  191.  
  192.   char * VD_base = 0; /* beginning of range for which above tables are kept. */
  193.  
  194.   XR_VDBuf vDCurrentBuf = 0;  /* Current buffer for XR_VDOp. */
  195.  
  196. /* Lists of blocks waiting to be reclaimed */
  197. struct hblk * GC_reclaim_list[MAXOBJSZ+1] = {(struct hblk *)0};
  198. struct hblk * GC_areclaim_list[MAXOBJSZ+1] = {(struct hblk *)0};
  199.  
  200. /* Number of reclaim list invalidations */
  201. unsigned long GC_reclaim_inval_counter = 0;
  202.  
  203. /* Maps of heap block layouts. */
  204. char * GC_obj_map[MAXOBJSZ+1] = {(char *)0};
  205.  
  206. # ifdef RESTRICTED_INTERIOR_POINTERS
  207.       char GC_valid_offsets[MAX_OFFSET+1] = {0};
  208. # endif   
  209.    
  210. # ifdef SEPARATE_HEADERS
  211.     /* List of all header areas.  Should be private but needs   */
  212.     /* to not be scanned.                      */
  213. #     define MAX_HEADER_AREAS 256
  214.       struct hdr_area {
  215.         char * ha_start;
  216.         char * ha_end;
  217.       } GC_header_areas[MAX_HEADER_AREAS] = {{0,0}};
  218.     /* Header table.                        */
  219.       struct hblkhdr * GC_headers[MAP_SIZE] = {(struct hblkhdr *)0};
  220. # endif
  221.  
  222. char GC_map_cache[MAP_CACHE_SZ][HBLKSIZE/BYTES_PER_WORD] = {{0}};
  223.                      /* Space used to hold GC_obj_map maps */    
  224.  
  225. # ifdef MERGE_SIZES                     
  226.     long GC_size_map[MAXOBJSZ+1] = {0};
  227. # endif
  228.  
  229. char GC_dirty_bits[MAP_SIZE + (MAX_DATA_SIZE/HBLKSIZE)] = {0};
  230.  
  231. word GC_last_global = 0;
  232.  
  233. /* Stuff below here is private to the collector, but should be used as a */
  234. /* root for marking.                             */
  235.  
  236. /* List of finalizable objects: */
  237. # ifdef FINALIZE
  238.   XR_FinalizationHandle GC_finalizeListHead = (XR_FinalizationHandle)0;
  239. # endif /* FINALIZE */
  240.  
  241. struct uncollectable_structure * GC_pin_head =
  242.                                (struct uncollectable_structure *) 0;
  243.                     /* Head of list of uncollectable objects. */                    
  244.            
  245.